<template>
  <div class="authority">
    <el-card class="box-card">
      <el-breadcrumb separator-class="el-icon-arrow-right">
        <el-breadcrumb-item :to="{ path: '/interface' }"
          >首页</el-breadcrumb-item
        >
        <el-breadcrumb-item>订单管理</el-breadcrumb-item>
        <el-breadcrumb-item>订单列表</el-breadcrumb-item>
      </el-breadcrumb>
      <!-- 搜索商品 -->
      <div class="users_title">
        <div class="ipt">
          <el-input
            placeholder="请输入内容"
            v-model="params.query"
            class="input-with-select"
            @keydown.enter="user_search1"
          >
            <el-button
              slot="append"
              icon="el-icon-search"
              @click="user_search"
            ></el-button>
          </el-input>
        </div>
      </div>
      <!-- 商品列表 -->
      <div>
        <el-table
          :data="tableData"
          height="430px"
          border
          size="small"
          style="width: 100%"
        >
          <el-table-column
            type="index"
            align="center"
            width="50px"
            label="序号"
          >
          </el-table-column>
          <el-table-column
            prop="order_number"
            align="center"
            label="订单编号"
            width="400px"
          >
          </el-table-column>
          <el-table-column prop="order_price" align="center" label="订单价格">
            <template slot-scope="priceVal">
              {{ priceVal.row.order_price | price }}
            </template>
          </el-table-column>
          <el-table-column prop="order_pay" align="center" label="是否付款">
            <template slot-scope="priceVal">
              <el-tag v-if="priceVal.row.order_pay == 1">已付款</el-tag>
              <el-tag v-else type="danger">未付款</el-tag>
            </template>
          </el-table-column>
          <el-table-column prop="is_send" align="center" label="是否发货">
            <!-- <template slot-scope="timeVal">
              {{ timeVal.row.add_time | timeFormat }}
            </template> -->
          </el-table-column>
          <el-table-column prop="create_time" align="center" label="下单时间">
            <template slot-scope="timeVal">
              {{ timeVal.row.create_time | timeFormat }}
            </template>
          </el-table-column>
          <el-table-column align="center" label="操作">
            <template slot-scope="EachData">
              <!-- 编辑订单 -->
              <el-button
                type="primary"
                size="mini"
                icon="el-icon-edit"
                @click="editArticle(EachData.row.goods_id)"
              ></el-button>
              <!-- 物流进度 -->
              <el-button
                :disabled="EachData.row.is_send == '是' ? false : true"
                type="success"
                size="mini"
                icon="el-icon-location-outline"
                @click="delArticle(EachData.row)"
              ></el-button>
            </template>
          </el-table-column>
        </el-table>
      </div>
      <!-- 分页 -->
      <div class="block">
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="currentPage4"
          :page-sizes="[10, 15, 20, 25]"
          :page-size="10"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total"
        >
        </el-pagination>
      </div>
    </el-card>
    <!-- 修改地址对话框 -->
    <el-dialog title="修改地址" :visible.sync="editCommodity" width="30%">
      <el-form
        :model="addressForm"
        :rules="rules"
        ref="editCommodityForm"
        label-width="100px"
        class="demo-ruleForm"
      >
        <el-form-item label="省市区/县" prop="address1">
          <el-cascader
            v-model="addressForm.address1"
            :options="cityData"
            @change="btn"
          ></el-cascader>
        </el-form-item>
        <el-form-item label="详细地址" prop="address2">
          <el-input v-model="addressForm.address2"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="editCommodity = false">取 消</el-button>
        <el-button type="primary" @click="editDity">确 定</el-button>
      </span>
    </el-dialog>
    <!-- 物流信息 -->
    <el-dialog title="物流进度" :visible.sync="process" width="50%">
      <el-timeline :reverse="reverse">
        <el-timeline-item
          v-for="(activity, index) in activities"
          :key="index"
          :timestamp="activity.time"
        >
          {{ activity.context }}
        </el-timeline-item>
      </el-timeline>
    </el-dialog>
  </div>
</template>

<script>
import cityData from "../city.data-3.js";
export default {
  data() {
    return {
      //请求对象
      params: {
        query: "",
        pagenum: 1,
        pagesize: 10,
      },
      currentPage4: 0,
      total: 0,
      //商品列表
      tableData: [],
      //编辑商品对话框
      editCommodity: false,
      editId: 0,
      addressForm: {
        address1: "",
        address2: "",
      },
      rules: {
        address1: [{ required: true, message: "请输入地区", trigger: "blur" }],
        address2: [
          { required: true, message: "请输入详情地址", trigger: "blur" },
        ],
      },
      cityData: cityData,
      //物流进度
      process: false,
      reverse: false,
      activities: [],
    };
  },
  methods: {
    //获取地级市选中的节点
    btn() {
      this.addressForm.address2 = this.addressForm.address1;
    },
    //确定商品修改
    async editDity() {
      // let res = await this.axios.put(
      //   `goods/${this.editId}`,
      //   this.editCommodityForm
      // );
      console.log(this.addressForm.address1);
    },
    //编辑商品
    editArticle(id) {
      this.editCommodity = true;
      this.editId = id;
    },
    //物流进度
    delArticle(row) {
      this.process = true;
      console.log(row);
      this.axios.get(`/kuaidi/${1106975712662}`).then(
        (res) => {
          console.log(res);
          this.activities = res.data.data;
        },
        (err) => {
          console.log(err);
        }
      );
    },
    //根据id查询订单
    user_search1() {
      // 键盘事件
      this.user_search();
    },
    user_search() {
      this.axios.get(`orders/${this.params.query}`).then(
        (res) => {
          this.$message({
            message: "查询商品成功!",
            type: "success",
            center: "true",
          });
          console.log(this.tableData);
        },
        (err) => {
          console.error(err);
        }
      );
    },
    //获取订单列表
    commodityList() {
      this.axios
        .get("orders", {
          params: this.params,
        })
        .then(
          (res) => {
            console.log(res);
            this.tableData = res.data.data.goods;
            this.total = res.data.data.total;
          },
          (err) => {
            console.log(err);
          }
        );
    },
    //每页多少条数据
    handleSizeChange(val) {
      // console.log(`每页 ${val} 条`);
      this.params.pagesize = val;
      this.commodityList();
    },
    //获取当页的数值
    handleCurrentChange(val) {
      // console.log(`当前页: ${val}`);
      this.params.pagenum = val;
      this.commodityList();
    },
  },
  mounted() {
    this.commodityList();
  },
};
</script>

<style lang='less' scope>
.authority {
  width: 100%;
  .box-card {
    height: 82vh;
    //添加用户
    .users_title {
      width: 100%;
      height: 80px;
      display: flex;
      align-items: center;
      .el-form-item__label:before {
        content: "*";
        color: #f56c6c;
        margin-right: 4px;
      }
      .el-row {
        margin: 30px;
      }
      .ipt {
        .el-input__inner {
          width: 300px;
        }
      }
      .el-select .el-input {
        width: 100px;
      }
      .input-with-select .el-input-group__prepend {
        background-color: #fff;
      }
    }
    .btn {
      margin-top: 30px;
    }
    //角色列表
    .role {
      margin-top: 30px;
    }
    .border {
      margin: 10px 0px;
    }
    .block {
      height: 70px;
      display: flex;
      justify-content: center;
      align-items: center;
    }
  }
}
</style>